﻿using System.Collections;
using UnityEngine;

namespace Assets.AnimationPlayer.Scripts.Prefabs
{
    public class RoateImage : MonoBehaviour
    {

        public static string PrefabsName = "RoateImage";
        public static string PrefabsPath = "Prefabs/RoateImage";

        // Use this for initialization
        internal void Start()
        {
            name = PrefabsName;
            InitScale = transform.localScale;
            _scaleNumber = ScaleMax;
            BeginLoading();
        }
        #region 加载界面

        #endregion

        #region 定时器 每0.1秒更新一次
        public void BeginLoading()
        {
            StartCoroutine(OnThreadLoop());
        }

        public void StopLoading()
        {
            StopAllCoroutines();
        }

        public Vector3 InitScale = Vector3.one;
        public int Speed = 15;

        public float ScaleMax = 1.0f;
        public float ScaleMin = 0.5f;
        public float ScaleSpeed = 0.1f;
        private bool _scaleLarge;
        private float _scaleNumber = 1.0f;
        public IEnumerator OnThreadLoop()
        {
            while (true)
            {
                if (_scaleLarge)
                {
                    _scaleNumber += ScaleSpeed;
                    if (_scaleNumber >= ScaleMax)
                    {
                        _scaleNumber = ScaleMax;
                        _scaleLarge = false;
                    }
                }
                else
                {
                    _scaleNumber -= ScaleSpeed;
                    if (_scaleNumber <= ScaleMin)
                    {
                        _scaleNumber = ScaleMin;
                        _scaleLarge = true;
                    }
                }
                //transform.localScale = InitScale*_scaleNumber;
                var mRotation = transform.localRotation;
                transform.localRotation = Quaternion.Euler(0, 0, mRotation.eulerAngles.z - Speed);
                yield return new WaitForSeconds(0.1f);
            }
        }
        #endregion
    }
}